package file.gui;

import java.awt.*;
import java.awt.image.PackedColorModel;

import javax.swing.*;

public class GUI_ImageLabel extends JLabel {
	
	private static final long serialVersionUID = 1L;
	private Image image;
	private int width;
	
	GUI_ImageLabel(ImageIcon image,int width){
		super();
		this.image = image.getImage();
		this.width = width;
	}

	GUI_ImageLabel(Image image,int width){
		super();
		this.image = image;
		this.width = width;
	}
	
	public void setWidth(int width){
		this.width = width;
	}
	
	public int getWidth(){
		return width;
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		if(image.getWidth(labelFor)>getWidth()){
			int imgw = image.getWidth(labelFor);
			int imgh = image.getHeight(labelFor);
			int thisw = getWidth();
			setSize(new Dimension(thisw-30, (thisw-30)*imgh/imgw+10));
			setPreferredSize(new Dimension(thisw-30, (thisw-30)*imgh/imgw+10));
			g.drawImage(image, 0, 0, thisw-30, (thisw-30)*imgh/imgw, this);
		}else g.drawImage(image, 0, 0, this);
	}
	
}
